package com.haixiaoke.saas.enterprise.cleaner.controller;

import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.cleaner.domain.SweepProcessRecord;
import com.haixiaoke.saas.cleaner.service.ISweepProcessRecordService;
import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 打扫流程记录Controller
 *
 * @author xiaoilong
 * @date 2024-05-11
 */
@RestController
@RequestMapping("/enterprise/cleaner/sweepRecord")
public class EnterpriseSweepProcessRecordController extends BaseController {
    @Autowired
    private ISweepProcessRecordService sweepProcessRecordService;

    /**
     * 查询打扫流程记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SweepProcessRecord sweepProcessRecord) {
        startPage();
        List<SweepProcessRecord> list = sweepProcessRecordService.selectSweepProcessRecordList(sweepProcessRecord);
        return getDataTable(list);
    }

    /**
     * 导出打扫流程记录列表
     */
    @PostMapping("/export")
    @RepeatSubmit
    public void export(HttpServletResponse response, SweepProcessRecord sweepProcessRecord) {
        List<SweepProcessRecord> list = sweepProcessRecordService.selectSweepProcessRecordList(sweepProcessRecord);
        ExcelUtil<SweepProcessRecord> util = new ExcelUtil<SweepProcessRecord>(SweepProcessRecord.class);
        util.exportExcel(response, list, "打扫流程记录数据");
    }

    /**
     * 获取打扫流程记录详细信息
     */
    @GetMapping(value = "/{sweepProcessId}")
    public AjaxResult getInfo(@PathVariable("sweepProcessId") Long sweepProcessId) {
        return success(sweepProcessRecordService.selectSweepProcessRecordBySweepProcessId(sweepProcessId));
    }

    /**
     * 新增打扫流程记录
     */
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody SweepProcessRecord sweepProcessRecord) {
        return toAjax(sweepProcessRecordService.insertSweepProcessRecord(sweepProcessRecord));
    }

    /**
     * 修改打扫流程记录
     */
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@RequestBody SweepProcessRecord sweepProcessRecord) {
        return toAjax(sweepProcessRecordService.updateSweepProcessRecord(sweepProcessRecord));
    }

    /**
     * 删除打扫流程记录
     */
    @DeleteMapping("/{sweepProcessIds}")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] sweepProcessIds) {
        return toAjax(sweepProcessRecordService.deleteSweepProcessRecordBySweepProcessIds(sweepProcessIds));
    }
}
